package chapter8.quarter4;

import javax.swing.*;
import java.awt.*;

public class GlueAndStrut {
    private JFrame frame;
    private Box b1,b2,b3,b4;

    public static void main(String[] args) {
        GlueAndStrut that=new GlueAndStrut();
        that.go();
    }

    public void go() {
        frame=new JFrame("glue and strut example");
        Container contentPane=frame.getContentPane();
        contentPane.setLayout(new GridLayout(4,1));
        b1=Box.createHorizontalBox();
        b1.add(new JLabel("box1:"));
        b1.add(new JLabel("yes"));
        b1.add(new JLabel("no"));
        b1.add(new JLabel("cancel"));

        b2=Box.createHorizontalBox();
        b2.add(new JLabel("box2:"));
        b2.add(new JLabel("yes"));
        b2.add(new JLabel("no"));
        b2.add(Box.createHorizontalGlue());
        b2.add(new JLabel("cancel"));

        b3=Box.createHorizontalBox();
        b3.add(new JLabel("box3:"));
        b3.add(new JLabel("yes"));
        b3.add(new JLabel("no"));
        b3.add(Box.createHorizontalStrut(20));
        b3.add(new JLabel("cancel"));

        b4=Box.createHorizontalBox();
        b4.add(new JLabel("box4:"));
        b4.add(new JLabel("yes"));
        b4.add(new JLabel("no"));
        b4.add(Box.createRigidArea(new Dimension(50,90)));
        b4.add(new JLabel("cancel"));

        contentPane.add(b1);
        contentPane.add(b2);
        contentPane.add(b3);
        contentPane.add(b4);
        frame.setSize(300,200);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
